package logic

import (
	"context"
	"log"

	"goods/goods"
	"goods/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteGoodsSkuByIdLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteGoodsSkuByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteGoodsSkuByIdLogic {
	return &DeleteGoodsSkuByIdLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteGoodsSkuByIdLogic) DeleteGoodsSkuById(in *goods.DeleteGoodsSkuByIdRequest) (*goods.DeleteGoodsSkuByIdResponse, error) {
	// todo: add your logic here and delete this line
	for i := 0; i < len(in.Ids); i++ {
		err := l.svcCtx.GoodsSku.Delete(context.Background(), int64(in.Ids[i]))
		if err != nil {
			log.Println("删除商品规格失败")
			return &goods.DeleteGoodsSkuByIdResponse{Code: -1, Msg: "删除商品失败"}, err
		}
	}
	return &goods.DeleteGoodsSkuByIdResponse{Code: 200, Msg: "删除商品成功"}, nil
}
